var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        });
Object.defineProperty(i, "__esModule", {value: !0}), e("GlobalParam");
var r = e("CMD"),
    s = e("LoginProxy"),
    c = e("RoomVO"),
    l = (function (e) {
        function t() {
            var o = e.call(this, t.NAME, new c.default()) || this;
            return (o.isInit = !1), o;
        }
        return (
            a(t, e),
            (t.prototype.init = function (e, t) {
                t && t();
            }),
            (t.prototype.getPlayerInfo = function () {
                var e = game.appFacade.retrieveProxy(s.default.NAME);
                return {
                    name: e.loginVO.userInfo.nickName,
                    customPlayerStatus: 0,
                    customProfile: JSON.stringify({
                        realPlayer: !0,
                        avatarUrl: e.loginVO.userInfo.avatarUrl,
                        name: e.loginVO.userInfo.nickName,
                        skinInfo: e.loginVO.skinInfo,
                        skinColor: e.loginVO.skinColor.toHEX()
                    })
                };
            }),
            (t.prototype.sendMsgToGameServer = function (e) {
                this.roomVO.room.sendToGameSvr({data: e}, function (t) {
                    0 === t.code
                        ? game.debug("sendMsgToGameServer success", e)
                        : game.warn("sendMsgToGameServer fail", t);
                });
            }),
            (t.prototype.matchRoom = function () {
                var e = this,
                    o = {playerInfo: this.getPlayerInfo(), maxPlayers: 4, roomType: "0"};
                this.roomVO.room.matchRoom(o, function (o) {
                    game.log("匹配结果", o),
                        0 === o.code
                            ? e.sendNotification(t.ON_MATCH_ROOM_SUCCESS, o.data.roomInfo)
                            : e.sendNotification(t.ON_MATCH_ROOM_FAIL);
                });
            }),
            (t.prototype.exitRoom = function () {
                var e = this;
                this.roomVO.room.roomInfo &&
                    this.roomVO.room.roomInfo.id &&
                    (this.roomVO.room.roomInfo.owner === MGOBE.Player.id
                        ? this.roomVO.room.dismissRoom({}, function (o) {
                              0 === o.code && (game.log("解散成功"), e.sendNotification(t.ON_ROOM_DISMISS));
                          })
                        : this.roomVO.room.leaveRoom({}, function (o) {
                              0 === o.code &&
                                  (game.log("退房成功", e.roomVO.room.roomInfo.id),
                                  e.roomVO.room.initRoom(),
                                  e.sendNotification(t.ON_ROOM_LEAVE));
                          }));
            }),
            (t.prototype.matchPlayers = function (e) {
                var t = this.getPlayerInfo();
                t.matchAttributes = [];
                var o = {playerInfo: t, matchCode: e};
                this.roomVO.room.matchPlayers(o, function (e) {
                    0 === e.code ? console.log("请求成功") : console.log("请求失败", e.code);
                });
            }),
            (t.prototype.cancelPlayerMatch = function (e) {
                this.roomVO.room.cancelPlayerMatch({matchType: e}, function (e) {
                    0 === e.code ? console.log("请求成功") : console.log("请求失败", e.code);
                });
            }),
            (t.prototype.sendJoinGame = function () {
                this.roomVO.room.roomInfo.id && this.sendMsgToGameServer([r.C2SCMD.CMD_JOIN_GAME]);
            }),
            (t.prototype.sendReady = function () {
                this.roomVO.room.roomInfo.id && this.sendMsgToGameServer([r.C2SCMD.CMD_READY]);
            }),
            (t.prototype.startFrameSync = function () {
                this.roomVO.room.startFrameSync({}, function (e) {
                    0 === e.code ? game.log("startFrameSync success") : game.warn("startFrameSync fail", e);
                });
            }),
            (t.prototype.stopFrameSync = function () {
                this.roomVO.room.stopFrameSync({}, function (e) {
                    0 === e.code ? game.log("stopFrameSync success") : game.warn("stopFrameSync fail", e);
                });
            }),
            (t.prototype.sendFrame = function (e) {
                this.roomVO.room.roomInfo &&
                    this.roomVO.room.roomInfo.playerList.length > 0 &&
                    this.roomVO.room.sendFrame({data: e}, function (e) {
                        e.code;
                    });
            }),
            (t.prototype.sendMsgToAll = function (e, t) {
                this.roomVO.room.roomInfo &&
                    this.roomVO.room.roomInfo.playerList.length > 0 &&
                    this.roomVO.room.sendToClient({recvType: e, msg: t, recvPlayerList: []}, function () {});
            }),
            (t.prototype.onJoinRoom = function (e) {
                game.log("onJoinRoom", e), this.sendNotification(t.ON_JOIN_ROOM, e.data.roomInfo);
            }),
            (t.prototype.onLeaveRoom = function (e) {
                game.log("onLeaveRoom", e),
                    this.sendNotification(t.ON_LEAVE_ROOM, {
                        roomInfo: e.data.roomInfo,
                        leavePlayerId: e.data.leavePlayerId
                    });
            }),
            (t.prototype.onDismissRoom = function (e) {
                game.log("onDismissRoom", e), this.sendNotification(t.ON_ROOM_DISMISS);
            }),
            (t.prototype.onRecvFromGameSvr = function (e) {
                game.log("onRecvFromGameSvr", e);
                var o = e.data.data,
                    n = o[0],
                    i = o[1];
                this.sendNotification(t.ON_SERVER_MSG, {cmd: n, body: i});
            }),
            (t.prototype.onRecvFrame = function (e) {
                this.sendNotification(t.ON_FRAME_MSG, {frame: e.data.frame});
            }),
            (t.prototype.onRecvFromClient = function (e) {
                this.sendNotification(t.ON_CLIENT_MSG, e.data);
            }),
            (t.prototype.onStartFrameSync = function (e) {
                game.log("onStartFrameSync", e), this.sendNotification(t.ON_START_FRAME);
            }),
            (t.prototype.onStopFrameSync = function (e) {
                game.log("onStopFrameSync", e), this.sendNotification(t.ON_STOP_FRAME);
            }),
            (t.prototype.onMatch = function (e) {
                if ((console.log("onMatch", e), e.data.errCode === MGOBE.ErrCode.EC_OK))
                    return (
                        this.roomVO.room.initRoom(e.data.roomInfo),
                        void this.sendNotification(t.ON_MATCH_PLAYER_SUCCESS)
                    );
                this.sendNotification(t.ON_MATCH_PLAYER_FAIL);
            }),
            (t.prototype.onCancelMatch = function (e) {
                game.log("onCancelMatch", e), this.sendNotification(t.ON_MATCH_PLAYER_CANCEL);
            }),
            (t.prototype.getData = function () {
                return this.data;
            }),
            Object.defineProperty(t.prototype, "roomVO", {
                get: function () {
                    return this.data;
                },
                enumerable: !1,
                configurable: !0
            }),
            (t.NAME = "RoomProxy"),
            (t.ON_MATCH_PLAYER_SUCCESS = "ON_MATCH_PLAYER_SUCCESS"),
            (t.ON_MATCH_PLAYER_FAIL = "ON_MATCH_PLAYER_FAIL"),
            (t.ON_MATCH_PLAYER_CANCEL = "ON_MATCH_PLAYER_CANCEL"),
            (t.ON_MATCH_ROOM_SUCCESS = "ON_MATCH_ROOM_SUCCESS"),
            (t.ON_MATCH_ROOM_FAIL = "ON_MATCH_ROOM_FAIL"),
            (t.ON_ROOM_DISMISS = "ON_ROOM_DISMISS"),
            (t.ON_ROOM_LEAVE = "ON_ROOM_LEAVE"),
            (t.ON_SERVER_MSG = "ON_SERVER_MSG"),
            (t.ON_FRAME_MSG = "ON_FRAME_MSG"),
            (t.ON_CLIENT_MSG = "ON_CLIENT_MSG"),
            (t.ON_START_FRAME = "ON_START_FRAME"),
            (t.ON_STOP_FRAME = "ON_STOP_FRAME"),
            (t.ON_JOIN_ROOM = "ON_JOIN_ROOM"),
            (t.ON_LEAVE_ROOM = "ON_LEAVE_ROOM"),
            t
        );
    })(puremvc.Proxy);
i.default = l;
